package com.aidex.system.mapper;

import java.util.List;

import com.aidex.common.core.mapper.BasicTreeMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import com.aidex.common.core.domain.entity.SysMenu;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

public interface SysMenuMapper extends BasicTreeMapper<SysMenu> {

    @Override
    @Select("select * from sys_menu t ${ew.customSqlSegment}")
    @Result(column = "id", property = "children", one = @One(select = "com.aidex.system.mapper.SysMenuMapper.selectListByParentId"))
    @Result(column = "id", property = "id")
    List<SysMenu> selectList(@Param("ew") Wrapper<SysMenu> queryWrapper);

    @Select("select * from sys_menu t where t.parent_id = #{parentId} and t.del_flag = '0'")
    @Result(column = "id", property = "children", one = @One(select = "com.aidex.system.mapper.SysMenuMapper.selectListByParentId"))
    @Result(column = "id", property = "id")
    List<SysMenu> selectListByParentId(@Param("parentId") String parentId);

    @Select("select max(t.tree_sort) from sys_menu t where t.del_flag = 0 and t.parent_id = #{parentId}")
    Integer findMaxSort(@Param("parentId") String parentId);
}
